﻿<?php
if (!defined('WEB_ROOT')) { 
	exit;
}

// make sure a product id exists
if (isset($_GET['newsId']) && $_GET['newsId'] > 0) {
	$newsId = $_GET['newsId'];
} else {
	// redirect to index.php if product id is not present
	header('Location: index.php');
}

// get product info
$sql = "SELECT tt.Chude_id, Ten, Noidung, Tacgia, Tieude, Image
        FROM tbl_tintuc tt, tbl_chude cd
		WHERE tt.Tintuc_id = $newsId AND tt.Chude_id = cd.Chude_id";
$result = mysql_query($sql) or die('Cannot get News. ' . mysql_error());
$row    = mysql_fetch_assoc($result);
extract($row);

// get category list
$sql = "SELECT Chude_id, Chude
        FROM tbl_chude
		ORDER BY Chude_id";
$result = dbQuery($sql) or die('Cannot get News. ' . mysql_error());

$Chude = array();
while($row = dbFetchArray($result)) {
	list($Chude_id,$name) = $row;
	
	//if ($parentId == 0) {
		//$chude[$id] = array('name' => $name, 'children' => array());
	//} else {
		$Chude[$Chude_id]['children'][] = array('id' => $Chude_id, 'name' => $name);	
	}	

//echo '<pre>'; print_r($categories); echo '</pre>'; exit;

// build combo box options
$list = '';
	foreach ($Chude as $key => $value) {
		//$name     = $value['name'];
		$children = $value['children'];
		
		//$list .= "<optgroup label=\"$name\">"; 
		
		foreach ($children as $child) {
			$list .= "<option value=\"{$child['id']}\"";
			if ($child['id'] == $Chude_id) {
				$list.= " selected";
			}
			
			$list .= ">{$child['name']}</option>\r\n";
		}
		
		//$list .= "</optgroup>";
}
?> 
<form action="processNews.php?action=modifyNews&newsId=<?php echo $newsId; ?>" method="post" enctype="multipart/form-data" name="frmAddProduct" id="frmAddProduct">
 <p align="center" class="formTitle">Chỉnh sửa bản tin</p>
 
 <table width="100%" border="0" align="center" cellpadding="5" cellspacing="1" class="entryTable">
  <tr> 
   <td width="150" class="label">Chủ đề</td>
   <td class="content"> <select name="cboCategory" id="cboCategory" class="box">
     <option value="" selected>-- Chọn chủ đề --</option>
<?php
	echo $list;
?>	 
    </select></td>
  </tr>
  <tr> 
   <td width="150" class="label">Tên bản tin</td>
   <td class="content"> <input name="txtName" type="text" class="box" id="txtName" value="<?php echo $Ten; ?>" size="50" maxlength="100"></td>
  </tr>
  <tr> 
   <td width="150" class="label">Tiêu đề</td>
   <td class="content"><textarea name="txtQty" cols="70" rows="3" class="box" id="txtQty" ><?php echo $Tieude;  ?></textarea></td>
  </tr>
  <tr> 
   <td width="150" class="label">Nội dung</td>
   <td class="content"> <textarea name="mtxDescription" cols="70" rows="10" class="box" id="mtxDescription"><?php echo $Noidung; ?></textarea></td>
  </tr>
  <tr> 
   <td width="150" class="label">Tác giả</td>
   <td class="content"><input name="txtPrice" type="text" class="box" id="txtPrice" value="<?php echo $Tacgia; ?>" size="50" maxlength="100"> </td>
  </tr>
  <tr> 
   <td width="150" class="label">Hình ảnh</td>
   <td class="content"> <input name="fleImage" type="file" id="fleImage" class="box">
<?php
	if ($Image != '') {
?>
    <br>
    <img src="<?php echo WEB_ROOT . TINTUC_IMAGE_DIR . $Image; ?>"> &nbsp;&nbsp;<a href="javascript:deleteImage(<?php echo $newsId; ?>);">Xoá 
    Ảnh</a> 
    <?php
	}
?>    
    </td>
  </tr>
 </table>
 <p align="center"> 
  <input name="btnModifyProduct" type="button" id="btnModifyProduct" value="Chỉnh sửa" onClick="checkAddProductForm();" class="box">
  &nbsp;&nbsp;<input name="btnCancel" type="button" id="btnCancel" value="Huỷ bỏ" onClick="window.location.href='index.php';" class="box">  
 </p>
</form>